package de.tum.team26.eistpoll.client.UI;

import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

import de.tum.team26.eistpoll.client.EIST_POLL;

/**
 * Class to show the Loading Panel
 */
public class Loading extends UIElement{
	
	// UI Element
	Label lblHeadding = new Label("Inactive");
	VerticalPanel loadingPanel = new VerticalPanel(); // Login Container
	HorizontalPanel headder = new HorizontalPanel();
	Image tum = new Image();
	Image info = new Image();
	Image loading = new Image();
	Label lblErrMsg;
	
	// Controller
	EIST_POLL controller;
	
	/**
	 * Initialise Panel
	 * @param controller
	 */
	public Loading(EIST_POLL controller){
		this.controller = controller;

		tum.setStyleName("tumlogo");
		info.setStyleName("infologo");
		tum.setUrl("tum.gif");
		info.setUrl("info.gif");
		
		// add UI Elements
		headder.add(tum);
		headder.add(info);
		headder.setStyleName("headder");
		loadingPanel.add(headder);
		loading.setUrl("loading.gif");
		loading.setStyleName("loading");
		loadingPanel.add(loading);
		loadingPanel.addStyleName("container");
	}

	// As always
	@Override
	public VerticalPanel getContainer() {
		return loadingPanel;
	}

	@Override
	public void displayErrorMessage(String message) {
		if (lblErrMsg == null){
			lblErrMsg = new Label(message);
			lblErrMsg.setStyleName("error");
			loadingPanel.add(lblErrMsg);
		}
		else{
			lblErrMsg.setText(message);
		}
	}

}
